import React, { Component } from 'react';
import PropTypes from 'prop-types';

import Child from './child.jsx';

export default class LifeCycle extends Component {
  static childContextTypes = {
    propA: PropTypes.string,
    methodA: PropTypes.func,
  }

  getChildContext() {
    return {
      propA: 'propA',
      methodA: () => 'methodA'
    };
  }
  constructor(props) {
    super(props);
    this.state = {
      content: 'nihao',
    };
  }
  componentWillReceiveProps(nextProps) {
    console.log('will receive props', nextProps);
  }
  shouldComponentUpdate(nextProps, nextState) {
    console.log('should componentupdate', nextProps, nextState);
    return true;
  }
  componentWillMount() {
    console.log('will mount');
  }

  componentDidMount() {
    console.log('did mount');
  }

  componentWillUpdate(...rest) {
    console.log('will update', rest);
  }

  componentDidUpdate(...rest) {
    console.log('did update', rest);
  }

  handleClick = () => {
    this.setState({
      content: '我好'+ Date.now()
    });
  }
  render() {
    console.log('render');
    const { content } = this.state;
    return (
      <div onClick={this.handleClick}>
        {content}
        <Child content={content}></Child>
      </div>
    );
  }
  componentWillUnmount() {
    console.log('unmount');
  }
}